import 'package:flutter/material.dart';
import 'package:ninetyfour/l10n/app_localizations.dart';

class DetailCzInfoView extends StatelessWidget {
  final List<Map<String, dynamic>> models;
  final bool isScuuessPass;

  const DetailCzInfoView({
    super.key,
    required this.models,
    required this.isScuuessPass,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(left: 15, right: 15),
      padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            isScuuessPass
                ? AppLocalizations.of(context)!.rechargeInformation
                : AppLocalizations.of(context)!.purchaseInformation,
            style: const TextStyle(
              color: Color(0xFF252525),
              fontSize: 15,
            ),
          ),
          const SizedBox(height: 12),
          const Divider(height: 1, color: Color(0xFFF5F5F5)),
          const SizedBox(height: 12),
          ..._buildInfoItems(context),
        ],
      ),
    );
  }

  List<Widget> _buildInfoItems(BuildContext context) {
    final List<Widget> items = [];

    for (final model in models) {
      final type = model['type'] as String;
      final name = model['name'] as String;
      final value = model['value'] as String;

      final titleWidget = Text(
        name,
        style: const TextStyle(
          color: Color(0xFF333333),
          fontSize: 14,
        ),
      );

      final valueWidget = Text(
        value,
        style: const TextStyle(
          color: Color(0xFF666666),
          fontSize: 14,
        ),
        textAlign: TextAlign.right,
      );

      if (type == '3') {
        items.add(
          Padding(
            
            padding: const EdgeInsets.only(bottom: 20),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  width: 160,
                  child: titleWidget,
                ),
                Expanded(
                  child: Padding(
                    padding: const EdgeInsets.only(left: 15),
                    child: valueWidget,
                  ),
                ),
              ],
            ),
          ),
        );
      } else {
        items.add(
          Padding(
            padding: const EdgeInsets.only(bottom: 20),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(width: 170, child: titleWidget),
                Expanded(child: valueWidget),
              ],
            ),
          ),
        );
      }
    }

    return items;
  }
}